package com.ctg.behavior.calc.utils;

import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;

import com.ctg.behavior.common.calc.CtCalcPropertyType;
import com.ctg.behavior.common.ltv.CtLTVCell;

public class CtCalcUtils {

	public static Integer getPathNodeColumnIndex(String nodeKey) {
		int index = nodeKey.indexOf("-");
		if (index > 0) {
			return Integer.valueOf(nodeKey.substring(0, index));
		}
		return -1;
	}

	public static String buildLTVGroupByValues(LinkedHashMap<String, Object> oneResult, List<CtCalcPropertyType> byPropertis) {
		StringBuilder sbuf = new StringBuilder("[\"");
		for (CtCalcPropertyType property : byPropertis) {
			sbuf.append(String.valueOf(oneResult.get(property.getProperty())));
			sbuf.append("\",");
		}
		sbuf.replace(sbuf.length() - 1, sbuf.length(), "\"]");
		return sbuf.toString();
	}
	
	public static List<CtLTVCell> copyLTVCells(List<CtLTVCell> srcCells){
		List<CtLTVCell> targetCells = new ArrayList<>();
		for(CtLTVCell cell : srcCells) {
			CtLTVCell tcell = new CtLTVCell();
			tcell.setAmount(cell.getAmount());
			tcell.setPercent(cell.getPercent());
			targetCells.add(tcell);
		}
		return targetCells;
	}

}
